package com.zl.ots.utils;

import com.alibaba.fastjson2.JSON;

import java.util.List;

public class JsonUtil {

    public static String toJsonStr(Object obj) {
        if (obj instanceof Number) {
            return String.valueOf(obj);
        }
        return JSON.toJSONString(obj);
    }

    public static <T> T toBean(String jsonString, Class<T> beanClass) {
        return JSON.parseObject(jsonString, beanClass);
    }

    public static <T> List<T> toList(String jsonArray, Class<T> elementType) {
        return JSON.parseArray(jsonArray, elementType);
    }

}
